import { wechatrequest } from './API/request'
import { getStorageSync } from '../crossplatform/apiservice/storage'

/**
 * 所有城市列表
 */
export const getCityListRequest = () => {
  return wechatrequest.get('/city/getCityList', {
    data: {}
  })
}

/**
 * 历史城市列表
 */
export const getHistoryListRequest = () => {
  const userinfo = getStorageSync('userinfo')
  const userId = userinfo && userinfo.userId
  return wechatrequest.get('/city/getHistoryList', {
    data: {
      userId
    }
  })
}

/**
 * 新增历史城市
 */
export const insertCityHistoryRequest = ({ cityName }) => {
  const userinfo = getStorageSync('userinfo')
  const userId = userinfo && userinfo.userId
  if (userId) {
    return wechatrequest.postparams('/city/insertCityHistory', {
      data: {
        cityName,
        userId
      }
    })
  }
}

/**
 * 模糊搜索城市
 */
export const searchCityRequest = ({ keyWords }) => {
  return wechatrequest.get('/city/searchCity', {
    data: {
      keyWords
    }
  })
}

/**
 * 首页定位
 */
export const positioningRequest = ({ lat, lng }) => {
  return wechatrequest.get('/city/positioning', {
    data: {
      lat,
      lng
    }
  })
}

/**
 * 模糊搜索大学
 */
export const getSchoolList = () => {
  return wechatrequest.get(`/userArchive/findSchool`, {
    data: {}
  })
}

/**
 * 模糊搜索专业
 */
export const getMajorList = () => {
  return wechatrequest.get(`/userArchive/findProfession`, {
    data: {}
  })
}
